from typing import *


class Solution:
    def maxSubarrayLength(self, nums: List[int], k: int) -> int:
        h = Counter()
        l = 0
        ans = 0
        for i, v in enumerate(nums):
            h[v] += 1
            while h[v] > k:
                h[nums[l]] -= 1
                l += 1
            ans = max(ans, i - l + 1)
        return ans
